/**
 * 
 */
package pl.polsl.pum2.pj.math;

/**
 * Timer class with FPS counter.
 */
public class CustomTimer {

  private long  last;
  private long  current;

  private int   frames;
  private long  fpsTime;
  private float fps;

  public CustomTimer() {
    last = System.currentTimeMillis();
  }

  public long getIntervalMillis() {
    current = System.currentTimeMillis();
    long dt = current - last;
    last = current;

    ++frames;
    fpsTime += dt;
    if (fpsTime > 1000) {
      fps = frames * 1000 / fpsTime;
      frames = 0;
      fpsTime = 0;
    }
    return dt;
  }

  public float getFPS() {
    return fps;
  }
}
